package lunadevs.luna.module.exploits;

import org.lwjgl.input.Keyboard;

import lunadevs.luna.category.Category;
import lunadevs.luna.module.Module;
import lunadevs.luna.utils.TimeHelper;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.network.play.client.C07PacketPlayerDigging;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;

public class BedAura extends Module {

	public static Boolean active;
	 public TimeHelper delay;
	    private int xOffset;
	    private int zOffset;
	    private int yOffset;
	
	public BedAura() {
		super("BedAura", Keyboard.KEY_NONE, Category.EXPLOITS, false);
		this.delay = new TimeHelper();
	}

	@Override
	public void onUpdate() {
		if (!this.isEnabled) return;
		if (Minecraft.theWorld == null) {
            return;
        }
        this.xOffset = -5;
        while (this.xOffset < 6) {
            this.zOffset = -5;
            while (this.zOffset < 6) {
                this.yOffset = 5;
                while (this.yOffset > -5) {
                    final double x = Minecraft.thePlayer.posX + this.xOffset;
                    final double y = Minecraft.thePlayer.posY + this.yOffset;
                    final double z = Minecraft.thePlayer.posZ + this.zOffset;
                    final int id = Block.getIdFromBlock(Minecraft.theWorld.getBlockState(new BlockPos(x, y, z)).getBlock());
                    if (id == 26) {
                        this.smashBlock(new BlockPos(x, y, z));
                        break;
                    }
                    --this.yOffset;
                }
                ++this.zOffset;
            }
            ++this.xOffset;
        }
    }
    
    public void smashBlock(final BlockPos pos) {
        Minecraft.thePlayer.sendQueue.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, EnumFacing.UP));
        Minecraft.thePlayer.sendQueue.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, EnumFacing.UP));
    }



	@Override
    public void onEnable() {
        active = true;
        super.onEnable();
    }
 
    @Override
    public void onDisable() {
    active = false;
        super.onDisable();
    }
	
	@Override
	public String getValue() {
		return null;
	}

}
